<?php

namespace app\middleware;

use app\common\ApiStatus;
use app\service\HomeService;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class AuthCheck implements MiddlewareInterface
{
    public function process(Request $request, callable $next): Response
    {
        $method = $request->method();
        $uid    = request()->uid;
        if (empty($uid)) {
            $msg = ApiStatus::API_NEED_LOGIN->getStatus();
            if ($method == 'POST') {
                return json(['code' => ApiStatus::API_NEED_LOGIN->value, 'msg' => $msg]);
            } else {
                $login = 1;
                return view('public/jump', compact('msg', 'login'));
            }
        }
        return $next($request);
    }
}